import dao.EmployeeDao;

import java.sql.SQLException;
import java.util.Scanner;

public class EmployeeMain {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        //添加员工信息
        System.out.println("1.添加员工信息");
        System.out.println("2.员工信息列表");
        System.out.println("3.删除员工信息");
        System.out.println("4.修改员工信息");
        Scanner input = new Scanner(System.in);
        int choice = input.nextInt();
        //添加
        if (choice == 1) {
            addEmployee();
        }
        //员工列表
        if (choice == 2) {
            getAllEmployees();
        }
        //删除员工信息
        if (choice == 3) {
            deleteEmployeeById();
        }

        //删除员工信息
        if (choice == 4) {
            updateEmployeeById();
        }
    }

    private static void updateEmployeeById() throws SQLException, ClassNotFoundException {

        Scanner input = new Scanner(System.in);
        System.out.println("请输入要修改的员工Id");
        int id = input.nextInt();

        System.out.println("请输入员工姓名:");
        String username = input.next();
        if (username == null || username.isEmpty()) {
            System.out.println("员工姓名不能为空");
            return;
        }
        System.out.println("请输入部门名称:");
        String department = input.next();
        if (department == null || department.isEmpty()) {
            System.out.println("部门名称不能为空");
            return;
        }
        System.out.println("请输入绩效分:");
        int score = input.nextInt();

        int result = EmployeeDao.updateEmployeeById(id,username, department, score);
        if (result != 1) {
            System.out.println("修改失败");
        }
        System.out.println("修改成功");
    }

    //删除员工信息
    private static void deleteEmployeeById() throws SQLException, ClassNotFoundException {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入要删除的员工id:");
        int id = input.nextInt();
        int result = EmployeeDao.deleteEmployeeById(id);
        if (result != 1) {
            System.out.println("删除失败");
            return;
        }
        System.out.println("删除成功");
    }

    //员工列表
    private static void getAllEmployees() throws SQLException, ClassNotFoundException {

        EmployeeDao.getAllEmployees();
    }

    //添加
    private static void addEmployee() throws SQLException, ClassNotFoundException {
        System.out.println("添加员工信息");
        Scanner input = new Scanner(System.in);
        System.out.println("请输入员工姓名:");
        String username = input.next();
        if (username == null || username.isEmpty()) {
            System.out.println("员工姓名不能为空");
            return;
        }
        System.out.println("请输入部门名称:");
        String department = input.next();
        if (department == null || department.isEmpty()) {
            System.out.println("部门名称不能为空");
            return;
        }
        System.out.println("请输入绩效分:");
        int score = input.nextInt();

        int result = EmployeeDao.addEmployee(username, department, score);
        if (result != 1) {
            System.out.println("添加失败");
        }
        System.out.println("添加成功");
    }
}
